package com.supersit.greensproject.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.supersit.greensproject.R;
import com.supersit.greensproject.entity.UpdateInfo;

import java.util.List;

/**
 * Created by cong on 2016/7/14.
 */
public class VersionInfoAdapter extends BaseAdapter {
    private Context context;
    private List<UpdateInfo> data;
    private LayoutInflater inflater;

    public VersionInfoAdapter(Context context, List<UpdateInfo> data) {
        this.context = context;
        this.data = data;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        if (null == data || data.size() < 1)
            return 0;
        else
            return data.size();
    }

    @Override
    public Object getItem(int position) {
        if (null == data || data.size() < 1)
            return null;
        else
            return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHodler hodler;
        if (null == convertView) {
            hodler = new ViewHodler();
            convertView = inflater.inflate(R.layout.item_version_info, null);
            hodler.versionNumber = (TextView) convertView.findViewById(R.id.tv_version_number);
            hodler.versionInfo = (TextView) convertView.findViewById(R.id.tv_version_by);
            convertView.setTag(hodler);
        } else {
            hodler = (ViewHodler) convertView.getTag();
        }
        hodler.versionNumber.setText(data.get(position).getVersion());
        hodler.versionInfo.setText(data.get(position).getDescription());

        return convertView;
    }

    class ViewHodler {
        TextView versionNumber;
        TextView versionInfo;
    }
}
